package com.fenxiangtech.mall.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fenxiangtech.mall.web.controller.v1.ProductController;
import tech.ideashare.se.model.IS_JavaDoc;
import tech.ideashare.se.model.IS_WebProjectConfig;
import tech.ideashare.se.utils.is_generate.IS_GenDocUtils;


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

/**
 * @Author lixiang
 * @CreateTime 2018/6/29
 **/
public class DocTest {
    public static void main(String[] args) {

  //      readApi();
        requestApi();



    }

    public static void readApi(){
        List<IS_JavaDoc> is_javaDocs = Mall_GenDocUtils.generateDocByReflect(ProductController.class);
        String s = JSON.toJSONString(is_javaDocs);
        try {
            Files.writeString(Paths.get("api.json"),s);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void requestApi(){
        //从文件中读取
        try {
            String s1 = Files.readString(Paths.get("api.json"));
            List<IS_JavaDoc> array = JSONArray.parseArray(s1,IS_JavaDoc.class);
            var webConfig  = new IS_WebProjectConfig();
            webConfig.setRootWebUrl("http://localhost:8099/");
            IS_GenDocUtils.getResponse(array,webConfig);
            Files.writeString(Paths.get("aapi.json"),JSON.toJSONString(array, SerializerFeature.WriteMapNullValue));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
